<template>
  <el-dialog title="订单详情" :visible.sync="dialogVisible" width="30%">
    <h3>充值信息：</h3>
    <p>充值金额：{{ detail.amount }}</p>
    <p>赠送红包：{{ detail.redPackedAmount }}</p>

    <h3>会员信息:</h3>
    <p>会员名/姓名：{{ detail.memberName }} 会员卡：{{ detail.levelName }}</p>
    <p>会员ID：{{ detail.memberId }}</p>
    <p>手机号：{{ detail.phone }}</p>

    <h3>订单信息:</h3>
    <p>订单号：{{ detail.rechargeNumber }}</p>

    <p>订单状态：{{ detail.payStatus }}</p>
    <p>
      订单来源：{{
        detail.source == 1
          ? "小程序"
          : detail.source == 2
          ? "POS"
          : detail.source == 3
          ? "后台"
          : "未知来源"
      }}
    </p>
    <p>支付方式：{{ detail.payType }}</p>
    <p>第三方订单号：{{ detail.outTradeNo }}</p>
    <p>操作人：{{ detail.sysUserName }}</p>
    <p>订单价格：￥{{ detail.orderAmount }}</p>
    <p>创建时间：{{ detail.createTime }}</p>
    <p>支付时间：{{ detail.createTime }}</p>
    <span slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        size="small"
        @click="confirmOrder"
        v-if="detail.payStatus == '待支付'"
        >确认收款</el-button
      >
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { rechargeDetail, rechargeConfirm } from '@/config/api'
import { times, divide } from "@/utils/tools"

export default {
  data () {
    return {
      dialogVisible: false,
      detail: {}
    };
  },
  methods: {
    show (id) {
      this.getDeta(id)
      this.dialogVisible = true
    },
    getDeta (id) {
      rechargeDetail({ id }).then(res => {
        res.data.result.orderAmount = divide(res.data.result.orderAmount || 0, 100)
        res.data.result.amount = divide(res.data.result.amount || 0, 100)
        res.data.result.redPackedAmount = divide(res.data.result.redPackedAmount || 0, 100)
        this.detail = res.data.result
      })
    },
    confirmOrder (record) {
      this.$confirm('此操作将确认该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        rechargeConfirm({ rechargeNumber: this.detail.rechargeNumber }).then(res => {
          if (res.data.status == 200) {
            this.$parent.getData()
            this.$message({
              type: "success",
              message: "成功"
            });
            this.dialogVisible = false
          }

        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
};
</script>
<style scoped>
p {
  margin: 15px 0;
}
</style>